package com.sure.trafficvideo.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.sure.trafficvideo.R;
import com.sure.trafficvideo.model.VideoGroup;

public class VideoListAdapter extends BaseExpandableListAdapter {

	private Context mContext;
	private List<VideoGroup> itemList;
	private LayoutInflater inflater;

	public VideoListAdapter(Context context) {
		mContext = context;
		inflater = LayoutInflater.from(mContext);
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		if (itemList != null && itemList.get(groupPosition).pointList != null) {
			return itemList.get(groupPosition).pointList.get(childPosition);

		}

		return null;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
			ViewGroup parent) {
		TextView textView = new TextView(mContext);
		textView.setText(""+childPosition);
		return textView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		return 5;
	}

	@Override
	public VideoGroup getGroup(int groupPosition) {
		return itemList == null ? null : itemList.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		return itemList== null ? 0:itemList.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		return 0;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		View view = inflater.inflate(R.layout.group_item_view, null);
		TextView nameView = (TextView) view.findViewById(R.id.group_item_name);
		nameView.setText(getGroup(groupPosition).groupName);
		return view;
	}

	@Override
	public boolean hasStableIds() {
		return false;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		return false;
	}

	public void setData(ArrayList<VideoGroup> items) {
		itemList = items;
	}

}
